package com.z100h.supplychain.purchase.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.sys.utils.DictUtils;
import com.z100h.supplychain.sku.entity.Sku;
import com.z100h.supplychain.supplier.entity.Contract;
import com.z100h.supplychain.supplier.entity.Supplier;

/**
 * 采购单接口
 */
@Controller
@RequestMapping(value = "${adminPath}/test/purchase")
public class PurchaseController extends BaseController {

//	@Autowired
//	private RuntimeService runtimeService;

	@Autowired
	private TaskService taskService;

	/**
	 * 获取产品列表
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "test")
	@ResponseBody
	public void test(Model model) {

		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("applyUserId", "153151");
		variables.put("112", "2223");
//		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("SSD", variables);

		TaskQuery taskQuery = taskService.createTaskQuery().taskCandidateUser("1").orderByTaskCreateTime().desc();
		List<Task> tasks = taskQuery.list();
		for (Task t : tasks) {

			taskService.getVariables(t.getId()).get("112");

		}
	}

	/**
	 * 获取产品列表
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "sku")
	@ResponseBody
	public Map<String, Object> sku(Model model) {
		Map<String, Object> map = new HashMap<String, Object>();

		List<Sku> skuList = new ArrayList<Sku>();

		Sku sku1 = new Sku();
		sku1.setId("1");
		sku1.setProductName("绿萝");
		skuList.add(sku1);

		Sku sku2 = new Sku();
		sku2.setId("2");
		sku2.setProductName("柱绿萝");
		skuList.add(sku2);

		for (int i = 3; i < 100; i++) {
			Sku sku = new Sku();
			sku.setId(3 + "");
			sku.setProductName("发财树" + i);
			skuList.add(sku);
		}

		map.put("skuList", skuList);
		return map;
	}

	/**
	 * 供应商合同
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "contract")
	@ResponseBody
	public Map<String, Object> contract(Model model) {
		Map<String, Object> map = new HashMap<String, Object>();

		List<Contract> contractList = new ArrayList<Contract>();

		for (int i = 1; i < 500; i++) {
			Contract contract = new Contract();
			contract.setId(i + "");
			contract.setContractName("合同" + i);
			contractList.add(contract);
		}

		map.put("contractList", contractList);
		return map;
	}

	/**
	 * 供应商列表
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "supplier")
	@ResponseBody
	public Map<String, Object> supplier(Model model) {
		Map<String, Object> map = new HashMap<String, Object>();

		List<Supplier> supplierList = new ArrayList<Supplier>();

		for (int i = 1; i < 100; i++) {
			Supplier supplier = new Supplier();
			supplier.setId(i + "");
			supplier.setSupplierName("供应商" + i);
			supplierList.add(supplier);
		}

		map.put("supplierList", supplierList);
		return map;
	}

	/**
	 * 字典选项
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "dicData")
	@ResponseBody
	public Map<String, Object> dicData(Model model) {
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("payMethod", DictUtils.getDictList("sc_pay_method"));
		map.put("isTax", DictUtils.getDictList("sc_is_tax"));

		return map;
	}
}
